using AutoMapper;
using ChikovMF.Application.Features.SHOLF;
using ChikovMF.WebAPI.Hubs;
using ChikovMF.WebAPI.Models.Tags;
using MediatR;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.SignalR;

namespace Namespace
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class ProjectExamplesController : ControllerBase
    {
        [HttpPost]
        [DisableRequestSizeLimit,
            RequestFormLimits(MultipartBodyLengthLimit = int.MaxValue,
            ValueLengthLimit = int.MaxValue)]
        public async Task<ActionResult<IEnumerable<string>>> SHOLF(SHOLFDto model, [FromServices] IHubContext<SHOLFProgressHub> _progressHub)
        {
            var command = _mapper.Map<SHOLFCommand>(model);
            command.ProgressShow = new((float progress) =>
            {   
                if (model.ConnectionId != null)
                    _progressHub.Clients.Client(model.ConnectionId).SendAsync("UpdateLoadingBar", progress);
            });

            var projectId = await _mediator.Send(command);
            return Ok(projectId);
        }

        private readonly IMediator _mediator;
        private readonly IMapper _mapper;

        public ProjectExamplesController(IMediator mediator, IMapper mapper)
        {
            _mediator = mediator;
            _mapper = mapper;
        }
    }
}